package com.yunpeng.dynamic.page.dao.service.impl;

import com.yunpeng.cache.util.CodeGenerateCommonUtils;
import com.yunpeng.dynamic.page.common.constants.ConfigConstantValues;
import com.yunpeng.dynamic.page.dao.mapper.entity.ICommonMapper;
import com.yunpeng.dynamic.page.dao.service.ICodeGenerateCommonService;
import com.yunpeng.common.constant.CommonConstantValues;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * CodeGenerateCommonServiceImpl
 *
 * @author : Moore(hemw)
 * @date : 2020-04-16
 */
@Service
public class CodeGenerateCommonServiceImpl implements ICodeGenerateCommonService {

    /**
     * 日志对象
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenerateCommonServiceImpl.class);

    @Resource
    private ICommonMapper commonMapper;

    @Override
    /**
     * 生成代码（在途数量+1）
     *
     * @param tableName 表名
     * @return
     */
    public String generateCode(String tableName) {
        String codeStuff = String.format("%s", CommonConstantValues.CODE_FORMAT.format(new Date()));
        Integer seq = commonMapper.querySeqByCode(tableName, codeStuff);
        return CodeGenerateCommonUtils.INSTANCE.generateCode(ConfigConstantValues.APPLICATION_NAME, tableName, codeStuff, seq);
    }


    @Override
    /**
     * 在途数量减一
     *
     * @param tableName 表名
     */
    public void holdCountMinus(String tableName) {
        CodeGenerateCommonUtils.INSTANCE.holdCountMinus(ConfigConstantValues.APPLICATION_NAME, tableName);
    }


}
